using System.Xml;

namespace ServiceModel.Syndication.LEAP2A {
    /// <summary>
    /// Represents personal and organisational data which uses a service identifier
    /// See http://wiki.cetis.ac.uk/2009-03/LEAP2A_personal_data for more details
    /// </summary>
    public class LeapServiceData : LeapDataItem {
        /// <summary>
        /// Gets or sets the service ID.  See http://wiki.cetis.ac.uk/2009-03/LEAP2A_personal_data for a list.
        /// </summary>
        /// <value>The service.</value>
        public string Service {
            get;
            set;
        }

        protected override void WriteAttributes(XmlWriter writer, LeapFeed feed) {
            base.WriteAttributes(writer, feed);

            if (!string.IsNullOrEmpty(Service)) {
                writer.WriteAttributeString(
                    feed.LeapPredicatesNamespacePrefix,
                    "service",
                    feed.LeapPredicatesNamespace,
                    Service);
            }
        }

        protected override bool TryParseElement(XmlReader reader) {
            if (reader.LocalName == "persondata" || reader.LocalName == "orgdata") {
                this.Service = reader.GetAttribute(reader.Prefix + ":service");
            }

            return base.TryParseElement(reader);
        }
    }
}
